home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / etc / mono / 2.0 / DefaultWsdlHelpGenerator.aspx next >
Encoding:
Text File  |  2009-02-11  |  58.3 KB  |  1,851 lines

  1. <%--
  2. //
  3. // DefaultWsdlHelpGenerator.aspx: 
  4. //
  5. // Author:
  6. //   Lluis Sanchez Gual (lluis@ximian.com)
  7. //
  8. // (C) 2003 Ximian, Inc.  http://www.ximian.com
  9. //
  10. --%>
  11.  
  12. <%@ Import Namespace="System.Collections" %>
  13. <%@ Import Namespace="System.IO" %>
  14. <%@ Import Namespace="System.Xml.Serialization" %>
  15. <%@ Import Namespace="System.Xml" %>
  16. <%@ Import Namespace="System.Xml.Schema" %>
  17. <%@ Import Namespace="System.Web.Services" %>
  18. <%@ Import Namespace="System.Web.Services.Description" %>
  19. <%@ Import Namespace="System.Web.Services.Configuration" %>
  20. <%@ Import Namespace="System.Web.Configuration" %>
  21. <%@ Import Namespace="System" %>
  22. <%@ Import Namespace="System.Net" %>
  23. <%@ Import Namespace="System.Globalization" %>
  24. <%@ Import Namespace="System.Resources" %>
  25. <%@ Import Namespace="System.Diagnostics" %>
  26. <%@ Import Namespace="System.CodeDom" %>
  27. <%@ Import Namespace="System.CodeDom.Compiler" %>
  28. <%@ Import Namespace="Microsoft.CSharp" %>
  29. <%@ Import Namespace="Microsoft.VisualBasic" %>
  30. <%@ Import Namespace="System.Text" %>
  31. <%@ Import Namespace="System.Text.RegularExpressions" %>
  32. <%@ Import Namespace="System.Security.Cryptography.X509Certificates" %>
  33. <%@ Assembly name="System.Web.Services" %>
  34. <%@ Page debug="true" %>
  35.  
  36. <html>
  37. <script language="C#" runat="server">
  38.  
  39. ServiceDescriptionCollection descriptions;
  40. XmlSchemas schemas;
  41.  
  42. string WebServiceName;
  43. string WebServiceDescription;
  44. string PageName;
  45.  
  46. string DefaultBinding;
  47. ArrayList ServiceProtocols;
  48.  
  49. string CurrentOperationName;
  50. string CurrentOperationBinding;
  51. string OperationDocumentation;
  52. string CurrentOperationFormat;
  53. bool CurrentOperationSupportsTest;
  54. ArrayList InParams;
  55. ArrayList OutParams;
  56. string CurrentOperationProtocols;
  57. int CodeTextColumns = 95;
  58. BasicProfileViolationCollection ProfileViolations;
  59.  
  60. void Page_Load(object sender, EventArgs e)
  61. {
  62.     descriptions = (ServiceDescriptionCollection) Context.Items["wsdls"];
  63.     schemas = (XmlSchemas) Context.Items["schemas"];
  64.  
  65.     ServiceDescription desc = descriptions [0];
  66.     if (schemas.Count == 0) schemas = desc.Types.Schemas;
  67.     
  68.     Service service = desc.Services[0];
  69.     WebServiceName = service.Name;
  70.     if (desc.Bindings.Count == 0)
  71.         return;
  72.     
  73.     DefaultBinding = desc.Bindings[0].Name;
  74.     WebServiceDescription = service.Documentation;
  75.     if (WebServiceDescription == "" || WebServiceDescription == null)
  76.         WebServiceDescription = "Description has not been provided";
  77.     ServiceProtocols = FindServiceProtocols (null);
  78.     
  79.     CurrentOperationName = Request.QueryString["op"];
  80.     CurrentOperationBinding = Request.QueryString["bnd"];
  81.     if (CurrentOperationName != null) BuildOperationInfo ();
  82.  
  83.     PageName = HttpUtility.UrlEncode (Path.GetFileName(Request.Path), Encoding.UTF8);
  84.  
  85.     ArrayList list = new ArrayList ();
  86.     foreach (ServiceDescription sd in descriptions) {
  87.         foreach (Binding bin in sd.Bindings)
  88.             if (bin.Extensions.Find (typeof(SoapBinding)) != null) list.Add (bin);
  89.     }
  90.  
  91.     BindingsRepeater.DataSource = list;
  92.     Page.DataBind();
  93.     
  94.     ProfileViolations = new BasicProfileViolationCollection ();
  95.     foreach (WsiProfilesElement claims in ((WebServicesSection) WebConfigurationManager.GetSection("system.web/webServices")).ConformanceWarnings)
  96.         if (claims.Name != WsiProfiles.None)
  97.             WebServicesInteroperability.CheckConformance (claims.Name, descriptions, ProfileViolations);
  98. }
  99.  
  100. void BuildOperationInfo ()
  101. {
  102.     InParams = new ArrayList ();
  103.     OutParams = new ArrayList ();
  104.     
  105.     Port port = FindPort (CurrentOperationBinding, null);
  106.     Binding binding = descriptions.GetBinding (port.Binding);
  107.     
  108.     PortType portType = descriptions.GetPortType (binding.Type);
  109.     Operation oper = FindOperation (portType, CurrentOperationName);
  110.     
  111.     OperationDocumentation = oper.Documentation;
  112.     if (OperationDocumentation == null || OperationDocumentation == "")
  113.         OperationDocumentation = "No additional remarks";
  114.     
  115.     foreach (OperationMessage opm in oper.Messages)
  116.     {
  117.         if (opm is OperationInput)
  118.             BuildParameters (InParams, opm);
  119.         else if (opm is OperationOutput)
  120.             BuildParameters (OutParams, opm);
  121.     }
  122.     
  123.     // Protocols supported by the operation
  124.     CurrentOperationProtocols = "";
  125.     ArrayList prots = FindServiceProtocols (CurrentOperationName);
  126.     for (int n=0; n<prots.Count; n++) {
  127.         if (n != 0) CurrentOperationProtocols += ", ";
  128.         CurrentOperationProtocols += (string) prots[n];
  129.     }
  130.     
  131.     WebServiceProtocols testProtocols = WebServiceProtocols.HttpGet | WebServiceProtocols.HttpPost;
  132.     if (Context.Request.IsLocal)
  133.         testProtocols |= WebServiceProtocols.HttpPostLocalhost;
  134.     CurrentOperationSupportsTest = (WebServicesSection.Current.EnabledProtocols & testProtocols) != 0;
  135.  
  136.     // Operation format
  137.     OperationBinding obin = FindOperation (binding, CurrentOperationName);
  138.     if (obin != null)
  139.         CurrentOperationFormat = GetOperationFormat (obin);
  140.  
  141.     InputParamsRepeater.DataSource = InParams;
  142.     InputFormParamsRepeater.DataSource = InParams;
  143.     OutputParamsRepeater.DataSource = OutParams;
  144. }
  145.  
  146. void BuildParameters (ArrayList list, OperationMessage opm)
  147. {
  148.     Message msg = descriptions.GetMessage (opm.Message);
  149.     if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  150.     {
  151.         MessagePart part = msg.Parts[0];
  152.         XmlSchemaComplexType ctype;
  153.         if (part.Element == XmlQualifiedName.Empty)
  154.         {
  155.             ctype = (XmlSchemaComplexType) schemas.Find (part.Type, typeof(XmlSchemaComplexType));
  156.         }
  157.         else
  158.         {
  159.             XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  160.             ctype = (XmlSchemaComplexType) elem.SchemaType;
  161.         }
  162.         XmlSchemaSequence seq = ctype.Particle as XmlSchemaSequence;
  163.         if (seq == null) return;
  164.         
  165.         foreach (XmlSchemaObject ob in seq.Items)
  166.         {
  167.             Parameter p = new Parameter();
  168.             p.Description = "No additional remarks";
  169.             
  170.             if (ob is XmlSchemaElement)
  171.             {
  172.                 XmlSchemaElement selem = GetRefElement ((XmlSchemaElement)ob);
  173.                 p.Name = selem.Name;
  174.                 p.Type = selem.SchemaTypeName.Name;
  175.             }
  176.             else
  177.             {
  178.                 p.Name = "Unknown";
  179.                 p.Type = "Unknown";
  180.             }
  181.             list.Add (p);
  182.         }
  183.     }
  184.     else
  185.     {
  186.         foreach (MessagePart part in msg.Parts)
  187.         {
  188.             Parameter p = new Parameter ();
  189.             p.Description = "No additional remarks";
  190.             p.Name = part.Name;
  191.             if (part.Element == XmlQualifiedName.Empty)
  192.                 p.Type = part.Type.Name;
  193.             else
  194.             {
  195.                 XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (part.Element, typeof(XmlSchemaElement));
  196.                 p.Type = elem.SchemaTypeName.Name;
  197.             }
  198.             list.Add (p);
  199.         }
  200.     }
  201. }
  202.  
  203. string GetOperationFormat (OperationBinding obin)
  204. {
  205.     string format = "";
  206.     SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  207.     if (sob != null) {
  208.         format = sob.Style.ToString ();
  209.         SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  210.         if (sbb != null)
  211.             format += " / " + sbb.Use;
  212.     }
  213.     return format;
  214. }
  215.  
  216. XmlSchemaElement GetRefElement (XmlSchemaElement elem)
  217. {
  218.     if (!elem.RefName.IsEmpty)
  219.         return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  220.     else
  221.         return elem;
  222. }
  223.  
  224. ArrayList FindServiceProtocols(string operName)
  225. {
  226.     ArrayList table = new ArrayList ();
  227.     Service service = descriptions[0].Services[0];
  228.     foreach (Port port in service.Ports)
  229.     {
  230.         string prot = null;
  231.         Binding bin = descriptions.GetBinding (port.Binding);
  232.         if (bin.Extensions.Find (typeof(SoapBinding)) != null)
  233.             prot = "Soap";
  234.         else 
  235.         {
  236.             HttpBinding hb = (HttpBinding) bin.Extensions.Find (typeof(HttpBinding));
  237.             if (hb != null && hb.Verb == "POST") prot = "HttpPost";
  238.             else if (hb != null && hb.Verb == "GET") prot = "HttpGet";
  239.         }
  240.         
  241.         if (prot != null && operName != null)
  242.         {
  243.             if (FindOperation (bin, operName) == null)
  244.                 prot = null;
  245.         }
  246.  
  247.         if (prot != null && !table.Contains (prot))
  248.             table.Add (prot);
  249.     }
  250.     return table;
  251. }
  252.  
  253. Port FindPort (string portName, string protocol)
  254. {
  255.     Service service = descriptions[0].Services[0];
  256.     foreach (Port port in service.Ports)
  257.     {
  258.         if (portName == null)
  259.         {
  260.             Binding binding = descriptions.GetBinding (port.Binding);
  261.             if (GetProtocol (binding) == protocol) return port;
  262.         }
  263.         else if (port.Name == portName)
  264.             return port;
  265.     }
  266.     return null;
  267. }
  268.  
  269. string GetProtocol (Binding binding)
  270. {
  271.     if (binding.Extensions.Find (typeof(SoapBinding)) != null) return "Soap";
  272.     HttpBinding hb = (HttpBinding) binding.Extensions.Find (typeof(HttpBinding));
  273.     if (hb == null) return "";
  274.     if (hb.Verb == "POST") return "HttpPost";
  275.     if (hb.Verb == "GET") return "HttpGet";
  276.     return "";
  277. }
  278.  
  279.  
  280. Operation FindOperation (PortType portType, string name)
  281. {
  282.     foreach (Operation oper in portType.Operations) {
  283.         if (oper.Messages.Input.Name != null) {
  284.             if (oper.Messages.Input.Name == name) return oper;
  285.         }
  286.         else
  287.             if (oper.Name == name) return oper;
  288.     }
  289.         
  290.     return null;
  291. }
  292.  
  293. OperationBinding FindOperation (Binding binding, string name)
  294. {
  295.     foreach (OperationBinding oper in binding.Operations) {
  296.         if (oper.Input.Name != null) {
  297.             if (oper.Input.Name == name) return oper;
  298.         }
  299.         else 
  300.             if (oper.Name == name) return oper;
  301.     }
  302.         
  303.     return null;
  304. }
  305.  
  306. string FormatBindingName (string name)
  307. {
  308.     if (name == DefaultBinding) return "Methods";
  309.     else return "Methods for binding<br>" + name;
  310. }
  311.  
  312. string GetOpName (object op)
  313. {
  314.     OperationBinding ob = op as OperationBinding;
  315.     if (ob == null) return "";
  316.     if (ob.Input.Name != null) return ob.Input.Name;
  317.     else return ob.Name;
  318. }
  319.  
  320. bool HasFormResult
  321. {
  322.     get { return Request.QueryString ["ext"] == "testform"; }
  323. }
  324.  
  325. class NoCheckCertificatePolicy : ICertificatePolicy {
  326.     public bool CheckValidationResult (ServicePoint a, X509Certificate b, WebRequest c, int d)
  327.     {
  328.         return true;
  329.     }
  330. }
  331.  
  332. string GetTestResult ()
  333.     if (!HasFormResult) return null;
  334.     
  335.     bool fill = false;
  336.     string qs = "";
  337.     for (int n=0; n<Request.QueryString.Count; n++)
  338.     {
  339.         if (fill) {
  340.             if (qs != "") qs += "&";
  341.             qs += Request.QueryString.GetKey(n) + "=" + Server.UrlEncode (Request.QueryString [n]);
  342.         }
  343.         if (Request.QueryString.GetKey(n) == "ext") fill = true;
  344.     }
  345.         
  346.     string location = null;
  347.     ServiceDescription desc = descriptions [0];
  348.     Service service = desc.Services[0];
  349.     foreach (Port port in service.Ports)
  350.         if (port.Name == CurrentOperationBinding)
  351.         {
  352.             SoapAddressBinding sbi = (SoapAddressBinding) port.Extensions.Find (typeof(SoapAddressBinding));
  353.             if (sbi != null)
  354.                 location = sbi.Location;
  355.         }
  356.  
  357.     if (location == null) 
  358.         return "Could not locate web service";
  359.     
  360.     try
  361.     {
  362.         string url = location + "/" + CurrentOperationName;
  363.         Uri uri = new Uri (url);
  364.         WebRequest req;
  365.         if (CurrentOperationProtocols.IndexOf ("HttpGet") < 0) {
  366.             req = WebRequest.Create (url);
  367.             req.Method="POST";
  368.             if (!String.IsNullOrEmpty (qs)) {
  369.                 req.ContentType = "application/x-www-form-urlencoded";
  370.                 byte [] postBuffer = Encoding.UTF8.GetBytes (qs);
  371.                 req.ContentLength = postBuffer.Length;
  372.                 using (Stream requestStream = req.GetRequestStream())
  373.                     requestStream.Write (postBuffer, 0, postBuffer.Length);
  374.             }
  375.         }
  376.         else
  377.             req = WebRequest.Create (url + "?" + qs);
  378.         if (url.StartsWith ("https:"))
  379.             ServicePointManager.CertificatePolicy = new NoCheckCertificatePolicy ();
  380.         HttpCookieCollection cookies = Request.Cookies;
  381.         int last = cookies.Count;
  382.         if (last > 0) {
  383.             CookieContainer container = new CookieContainer ();
  384.             for (int i = 0; i < last; i++) {
  385.                 HttpCookie hcookie = cookies [i];
  386.                 Cookie cookie = new Cookie (hcookie.Name, hcookie.Value, hcookie.Path, hcookie.Domain);
  387.                 container.Add (uri, cookie);
  388.             }
  389.             ((HttpWebRequest) req).CookieContainer = container;
  390.         }
  391.         WebResponse resp = req.GetResponse();
  392.         StreamReader sr = new StreamReader (resp.GetResponseStream());
  393.         string s = sr.ReadToEnd ();
  394.         sr.Close ();
  395.         return "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  396.     }
  397.     catch (Exception ex)
  398.     { 
  399.         string res = "<b style='color:red'>" + ex.Message + "</b>";
  400.         WebException wex = ex as WebException;
  401.         if (wex != null)
  402.         {
  403.             WebResponse resp = wex.Response;
  404.             if (resp != null) {
  405.                 StreamReader sr = new StreamReader (resp.GetResponseStream());
  406.                 string s = sr.ReadToEnd ();
  407.                 sr.Close ();
  408.                 res += "<div class='code-xml'>" + ColorizeXml(WrapText(s,CodeTextColumns)) + "</div>";
  409.             }
  410.         }
  411.         return res;
  412.     }
  413. }
  414.  
  415. string GenerateOperationMessages (string protocol, bool generateInput)
  416. {
  417.     if (!IsOperationSupported (protocol)) return "";
  418.     
  419.     Port port;
  420.     if (protocol != "Soap") port = FindPort (null, protocol);
  421.     else port = FindPort (CurrentOperationBinding, null);
  422.     
  423.     Binding binding = descriptions.GetBinding (port.Binding);
  424.     OperationBinding obin = FindOperation (binding, CurrentOperationName);
  425.     PortType portType = descriptions.GetPortType (binding.Type);
  426.     Operation oper = FindOperation (portType, CurrentOperationName);
  427.     
  428.     HtmlSampleGenerator sg = new HtmlSampleGenerator (descriptions, schemas);
  429.     string txt = sg.GenerateMessage (port, obin, oper, protocol, generateInput);
  430.     if (protocol == "Soap") txt = WrapText (txt,CodeTextColumns);
  431.     txt = ColorizeXml (txt);
  432.     txt = txt.Replace ("@placeholder!","<span class='literal-placeholder'>");
  433.     txt = txt.Replace ("!placeholder@","</span>");
  434.     return txt;
  435. }
  436.  
  437. bool IsOperationSupported (string protocol)
  438. {
  439.     if (CurrentPage != "op" || CurrentTab != "msg") return false;
  440.     if (protocol == "Soap") return true;
  441.  
  442.     Port port = FindPort (null, protocol);
  443.     if (port == null) return false;
  444.     Binding binding = descriptions.GetBinding (port.Binding);
  445.     if (binding == null) return false;
  446.     return FindOperation (binding, CurrentOperationName) != null;
  447. }
  448.  
  449. //
  450. // Proxy code generation
  451. //
  452.  
  453. string GetProxyCode ()
  454. {
  455.     CodeNamespace codeNamespace = new CodeNamespace();
  456.     CodeCompileUnit codeUnit = new CodeCompileUnit();
  457.     
  458.     codeUnit.Namespaces.Add (codeNamespace);
  459.  
  460.     ServiceDescriptionImporter importer = new ServiceDescriptionImporter();
  461.     
  462.     foreach (ServiceDescription sd in descriptions)
  463.         importer.AddServiceDescription(sd, null, null);
  464.  
  465.     foreach (XmlSchema sc in schemas)
  466.         importer.Schemas.Add (sc);
  467.  
  468.     importer.Import(codeNamespace, codeUnit);
  469.  
  470.     string langId = Request.QueryString ["lang"];
  471.     if (langId == null || langId == "") langId = "cs";
  472.     CodeDomProvider provider = GetProvider (langId);
  473.     ICodeGenerator generator = provider.CreateGenerator();
  474.     CodeGeneratorOptions options = new CodeGeneratorOptions();
  475.     
  476.     StringWriter sw = new StringWriter ();
  477.     generator.GenerateCodeFromCompileUnit(codeUnit, sw, options);
  478.  
  479.     return Colorize (WrapText (sw.ToString (), CodeTextColumns), langId);
  480. }
  481.  
  482. public string CurrentLanguage
  483. {
  484.     get {
  485.         string langId = Request.QueryString ["lang"];
  486.         if (langId == null || langId == "") langId = "cs";
  487.         return langId;
  488.     }
  489. }
  490.  
  491. public string CurrentProxytName
  492. {
  493.     get {
  494.         string lan = CurrentLanguage == "cs" ? "C#" : "Visual Basic";
  495.         return lan + " Client Proxy";
  496.     }
  497. }
  498.  
  499. private CodeDomProvider GetProvider(string langId)
  500. {
  501.     switch (langId.ToUpper())
  502.     {
  503.         case "CS": return new CSharpCodeProvider();
  504.         case "VB": return new VBCodeProvider();
  505.         default: return null;
  506.     }
  507. }
  508.  
  509. //
  510. // Document generation
  511. //
  512.  
  513. string GenerateDocument ()
  514. {
  515.     StringWriter sw = new StringWriter ();
  516.     
  517.     if (CurrentDocType == "wsdl")
  518.         descriptions [CurrentDocInd].Write (sw);
  519.     else if (CurrentDocType == "schema")
  520.         schemas [CurrentDocInd].Write (sw);
  521.         
  522.     return Colorize (WrapText (sw.ToString (), CodeTextColumns), "xml");
  523. }
  524.  
  525. public string CurrentDocType
  526. {
  527.     get { return Request.QueryString ["doctype"] != null ? Request.QueryString ["doctype"] : "wsdl"; }
  528. }
  529.  
  530. public int CurrentDocInd
  531. {
  532.     get { return Request.QueryString ["docind"] != null ? int.Parse (Request.QueryString ["docind"]) : 0; }
  533. }
  534.  
  535. public string CurrentDocumentName
  536. {
  537.     get {
  538.         if (CurrentDocType == "wsdl")
  539.             return "WSDL document for namespace \"" + descriptions [CurrentDocInd].TargetNamespace + "\"";
  540.         else
  541.             return "Xml Schema for namespace \"" + schemas [CurrentDocInd].TargetNamespace + "\"";
  542.     }
  543. }
  544.  
  545. //
  546. // Pages and tabs
  547. //
  548.  
  549. bool firstTab = true;
  550. ArrayList disabledTabs = new ArrayList ();
  551.  
  552. string CurrentTab
  553. {
  554.     get { return Request.QueryString["tab"] != null ? Request.QueryString["tab"] : "main" ; }
  555. }
  556.  
  557. string CurrentPage
  558. {
  559.     get { return Request.QueryString["page"] != null ? Request.QueryString["page"] : "main" ; }
  560. }
  561.  
  562. void WriteTabs ()
  563. {
  564.     if (CurrentOperationName != null)
  565.     {
  566.         WriteTab ("main","Overview");
  567.         WriteTab ("test","Test Form");
  568.         WriteTab ("msg","Message Layout");
  569.     }
  570. }
  571.  
  572. void WriteTab (string id, string label)
  573. {
  574.     if (!firstTab) Response.Write(" | ");
  575.     firstTab = false;
  576.     
  577.     string cname = CurrentTab == id ? "tabLabelOn" : "tabLabelOff";
  578.     Response.Write ("<a href='" + PageName + "?" + GetPageContext(null) + GetDataContext() + "tab=" + id + "' style='text-decoration:none'>");
  579.     Response.Write ("<span class='" + cname + "'>" + label + "</span>");
  580.     Response.Write ("</a>");
  581. }
  582.  
  583. string GetTabContext (string pag, string tab)
  584. {
  585.     if (tab == null) tab = CurrentTab;
  586.     if (pag == null) pag = CurrentPage;
  587.     if (pag != CurrentPage) tab = "main";
  588.     return "page=" + pag + "&tab=" + tab + "&"; 
  589. }
  590.  
  591. string GetPageContext (string pag)
  592. {
  593.     if (pag == null) pag = CurrentPage;
  594.     return "page=" + pag + "&"; 
  595. }
  596.  
  597. class Tab
  598. {
  599.     public string Id;
  600.     public string Label;
  601. }
  602.  
  603. //
  604. // Syntax coloring
  605. //
  606.  
  607. static string keywords_cs =
  608.     "(\\babstract\\b|\\bevent\\b|\\bnew\\b|\\bstruct\\b|\\bas\\b|\\bexplicit\\b|\\bnull\\b|\\bswitch\\b|\\bbase\\b|\\bextern\\b|" +
  609.     "\\bobject\\b|\\bthis\\b|\\bbool\\b|\\bfalse\\b|\\boperator\\b|\\bthrow\\b|\\bbreak\\b|\\bfinally\\b|\\bout\\b|\\btrue\\b|" +
  610.     "\\bbyte\\b|\\bfixed\\b|\\boverride\\b|\\btry\\b|\\bcase\\b|\\bfloat\\b|\\bparams\\b|\\btypeof\\b|\\bcatch\\b|\\bfor\\b|" +
  611.     "\\bprivate\\b|\\buint\\b|\\bchar\\b|\\bforeach\\b|\\bprotected\\b|\\bulong\\b|\\bchecked\\b|\\bgoto\\b|\\bpublic\\b|" +
  612.     "\\bunchecked\\b|\\bclass\\b|\\bif\\b|\\breadonly\\b|\\bunsafe\\b|\\bconst\\b|\\bimplicit\\b|\\bref\\b|\\bushort\\b|" +
  613.     "\\bcontinue\\b|\\bin\\b|\\breturn\\b|\\busing\\b|\\bdecimal\\b|\\bint\\b|\\bsbyte\\b|\\bvirtual\\b|\\bdefault\\b|" +
  614.     "\\binterface\\b|\\bsealed\\b|\\bvolatile\\b|\\bdelegate\\b|\\binternal\\b|\\bshort\\b|\\bvoid\\b|\\bdo\\b|\\bis\\b|" +
  615.     "\\bsizeof\\b|\\bwhile\\b|\\bdouble\\b|\\block\\b|\\bstackalloc\\b|\\belse\\b|\\blong\\b|\\bstatic\\b|\\benum\\b|" +
  616.     "\\bnamespace\\b|\\bstring\\b)";
  617.  
  618. static string keywords_vb =
  619.     "(\\bAddHandler\\b|\\bAddressOf\\b|\\bAlias\\b|\\bAnd\\b|\\bAndAlso\\b|\\bAnsi\\b|\\bAs\\b|\\bAssembly\\b|" +
  620.     "\\bAuto\\b|\\bBoolean\\b|\\bByRef\\b|\\bByte\\b|\\bByVal\\b|\\bCall\\b|\\bCase\\b|\\bCatch\\b|" +
  621.     "\\bCBool\\b|\\bCByte\\b|\\bCChar\\b|\\bCDate\\b|\\bCDec\\b|\\bCDbl\\b|\\bChar\\b|\\bCInt\\b|" +
  622.     "\\bClass\\b|\\bCLng\\b|\\bCObj\\b|\\bConst\\b|\\bCShort\\b|\\bCSng\\b|\\bCStr\\b|\\bCType\\b|" +
  623.     "\\bDate\\b|\\bDecimal\\b|\\bDeclare\\b|\\bDefault\\b|\\bDelegate\\b|\\bDim\\b|\\bDirectCast\\b|\\bDo\\b|" +
  624.     "\\bDouble\\b|\\bEach\\b|\\bElse\\b|\\bElseIf\\b|\\bEnd\\b|\\bEnum\\b|\\bErase\\b|\\bError\\b|" +
  625.     "\\bEvent\\b|\\bExit\\b|\\bFalse\\b|\\bFinally\\b|\\bFor\\b|\\bFriend\\b|\\bFunction\\b|\\bGet\\b|" +
  626.     "\\bGetType\\b|\\bGoSub\\b|\\bGoTo\\b|\\bHandles\\b|\\bIf\\b|\\bImplements\\b|\\bImports\\b|\\bIn\\b|" +
  627.     "\\bInherits\\b|\\bInteger\\b|\\bInterface\\b|\\bIs\\b|\\bLet\\b|\\bLib\\b|\\bLike\\b|\\bLong\\b|" +
  628.     "\\bLoop\\b|\\bMe\\b|\\bMod\\b|\\bModule\\b|\\bMustInherit\\b|\\bMustOverride\\b|\\bMyBase\\b|\\bMyClass\\b|" +
  629.     "\\bNamespace\\b|\\bNew\\b|\\bNext\\b|\\bNot\\b|\\bNothing\\b|\\bNotInheritable\\b|\\bNotOverridable\\b|\\bObject\\b|" +
  630.     "\\bOn\\b|\\bOption\\b|\\bOptional\\b|\\bOr\\b|\\bOrElse\\b|\\bOverloads\\b|\\bOverridable\\b|\\bOverrides\\b|" +
  631.     "\\bParamArray\\b|\\bPreserve\\b|\\bPrivate\\b|\\bProperty\\b|\\bProtected\\b|\\bPublic\\b|\\bRaiseEvent\\b|\\bReadOnly\\b|" +
  632.     "\\bReDim\\b|\\bREM\\b|\\bRemoveHandler\\b|\\bResume\\b|\\bReturn\\b|\\bSelect\\b|\\bSet\\b|\\bShadows\\b|" +
  633.     "\\bShared\\b|\\bShort\\b|\\bSingle\\b|\\bStatic\\b|\\bStep\\b|\\bStop\\b|\\bString\\b|\\bStructure\\b|" +
  634.     "\\bSub\\b|\\bSyncLock\\b|\\bThen\\b|\\bThrow\\b|\\bTo\\b|\\bTrue\\b|\\bTry\\b|\\bTypeOf\\b|" +
  635.     "\\bUnicode\\b|\\bUntil\\b|\\bVariant\\b|\\bWhen\\b|\\bWhile\\b|\\bWith\\b|\\bWithEvents\\b|\\bWriteOnly\\b|\\bXor\\b)";
  636.  
  637. string Colorize (string text, string lang)
  638. {
  639.     if (lang == "xml") return ColorizeXml (text);
  640.     else if (lang == "cs") return ColorizeCs (text);
  641.     else if (lang == "vb") return ColorizeVb (text);
  642.     else return text;
  643. }
  644.  
  645. string ColorizeXml (string text)
  646. {
  647.     text = text.Replace (" ", " ");
  648.     Regex re = new Regex ("\r\n|\r|\n");
  649.     text = re.Replace (text, "_br_");
  650.     
  651.     re = new Regex ("<\\s*(\\/?)\\s*([\\s\\S]*?)\\s*(\\/?)\\s*>");
  652.     text = re.Replace (text,"{blue:<$1}{maroon:$2}{blue:$3>}");
  653.     
  654.     re = new Regex ("\\{(\\w*):([\\s\\S]*?)\\}");
  655.     text = re.Replace (text,"<span style='color:$1'>$2</span>");
  656.  
  657.     re = new Regex ("\"(.*?)\"");
  658.     text = re.Replace (text,"\"<span style='color:purple'>$1</span>\"");
  659.  
  660.     
  661.     text = text.Replace ("\t", "     ");
  662.     text = text.Replace ("_br_", "<br>");
  663.     return text;
  664. }
  665.  
  666. string ColorizeCs (string text)
  667. {
  668.     text = text.Replace (" ", " ");
  669.  
  670.     text = text.Replace ("<", "<");
  671.     text = text.Replace (">", ">");
  672.  
  673.     Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  674.     text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  675.  
  676.     re = new Regex ("//(((.(?!\"</span>))|\"(((?!\").)*)\"</span>)*)(\r|\n|\r\n)");
  677.     text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  678.     
  679.     re = new Regex (keywords_cs);
  680.     text = re.Replace (text,"<span style='color:blue'>$1</span>");
  681.     
  682.     text = text.Replace ("\t","     ");
  683.     text = text.Replace ("\n","<br/>");
  684.     
  685.     return text;
  686. }
  687.  
  688. string ColorizeVb (string text)
  689. {
  690.     text = text.Replace (" ", " ");
  691.     
  692. /*    Regex re = new Regex ("\"((((?!\").)|\\\")*?)\"");
  693.     text = re.Replace (text,"<span style='color:purple'>\"$1\"</span>");
  694.  
  695.     re = new Regex ("'(((.(?!\"\\<\\/span\\>))|\"(((?!\").)*)\"\\<\\/span\\>)*)(\r|\n|\r\n)");
  696.     text = re.Replace (text,"<span style='color:green'>//$1</span><br/>");
  697.     
  698.     re = new Regex (keywords_vb);
  699.     text = re.Replace (text,"<span style='color:blue'>$1</span>");
  700. */    
  701.     text = text.Replace ("\t","     ");
  702.     text = text.Replace ("\n","<br/>");
  703.     return text;
  704. }
  705.  
  706. //
  707. // Helper methods and classes
  708. //
  709.  
  710. string GetDataContext ()
  711. {
  712.     return "op=" + CurrentOperationName + "&bnd=" + CurrentOperationBinding + "&";
  713. }
  714.  
  715. string GetOptionSel (string v1, string v2)
  716. {
  717.     string op = "<option ";
  718.     if (v1 == v2) op += "selected ";
  719.     return op + "value='" + v1 + "'>";
  720. }
  721.  
  722. string WrapText (string text, int maxChars)
  723. {
  724.     text =  text.Replace(" />","/>");
  725.     
  726.     string linspace = null;
  727.     int lincount = 0;
  728.     int breakpos = 0;
  729.     int linstart = 0;
  730.     bool inquotes = false;
  731.     char lastc = ' ';
  732.     string sublineIndent = "";
  733.     System.Text.StringBuilder sb = new System.Text.StringBuilder ();
  734.     for (int n=0; n<text.Length; n++)
  735.     {
  736.         char c = text [n];
  737.         
  738.         if (c=='\r' || c=='\n' || n==text.Length-1)
  739.         {
  740.             sb.Append (linspace + sublineIndent + text.Substring (linstart, n-linstart+1));
  741.             linspace = null;
  742.             lincount = 0;
  743.             linstart = n+1;
  744.             breakpos = linstart;
  745.             sublineIndent = "";
  746.             lastc = c;
  747.             continue;
  748.         }
  749.         
  750.         if (lastc==',' || lastc=='(')
  751.         {
  752.             if (!inquotes) breakpos = n;
  753.         }
  754.         
  755.         if (lincount > maxChars && breakpos >= linstart)
  756.         {
  757.             if (linspace != null)
  758.                 sb.Append (linspace + sublineIndent);
  759.             sb.Append (text.Substring (linstart, breakpos-linstart));
  760.             sb.Append ("\n");
  761.             sublineIndent = "     ";
  762.             lincount = linspace.Length + sublineIndent.Length + (n-breakpos);
  763.             linstart = breakpos;
  764.         }
  765.         
  766.         if (c==' ' || c=='\t')
  767.         {
  768.             if (!inquotes)
  769.                 breakpos = n;
  770.         }
  771.         else if (c=='"')
  772.         {
  773.             inquotes = !inquotes;
  774.         }
  775.         else 
  776.             if (linspace == null) {
  777.                 linspace = text.Substring (linstart, n-linstart);
  778.                 linstart = n;
  779.             }
  780.  
  781.         lincount++;
  782.         lastc = c;
  783.     }
  784.     return sb.ToString ();
  785. }
  786.  
  787. class Parameter
  788. {
  789.     string name;
  790.     string type;
  791.     string description;
  792.  
  793.     public string Name { get { return name; } set { name = value; } }
  794.     public string Type { get { return type; } set { type = value; } }
  795.     public string Description { get { return description; } set { description = value; } }
  796. }
  797.  
  798. public class HtmlSampleGenerator: SampleGenerator
  799. {
  800.     public HtmlSampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
  801.     : base (services, schemas)
  802.     {
  803.     }
  804.         
  805.     protected override string GetLiteral (string s)
  806.     {
  807.         return "@placeholder!" + s + "!placeholder@";
  808.     }
  809. }
  810.  
  811.  
  812.     public class SampleGenerator
  813.     {
  814.         protected ServiceDescriptionCollection descriptions;
  815.         protected XmlSchemas schemas;
  816.         XmlSchemaElement anyElement;
  817.         ArrayList queue;
  818.         SoapBindingUse currentUse;
  819.         XmlDocument document = new XmlDocument ();
  820.         
  821.         static readonly XmlQualifiedName anyType = new XmlQualifiedName ("anyType",XmlSchema.Namespace);
  822.         static readonly XmlQualifiedName arrayType = new XmlQualifiedName ("Array","http://schemas.xmlsoap.org/soap/encoding/");
  823.         static readonly XmlQualifiedName arrayTypeRefName = new XmlQualifiedName ("arrayType","http://schemas.xmlsoap.org/soap/encoding/");
  824.         const string SoapEnvelopeNamespace = "http://schemas.xmlsoap.org/soap/envelope/";
  825.         const string WsdlNamespace = "http://schemas.xmlsoap.org/wsdl/";
  826.         const string SoapEncodingNamespace = "http://schemas.xmlsoap.org/soap/encoding/";
  827.         
  828.         class EncodedType
  829.         {
  830.             public EncodedType (string ns, XmlSchemaElement elem) { Namespace = ns; Element = elem; }
  831.             public string Namespace;
  832.             public XmlSchemaElement Element;
  833.         }
  834.  
  835.         public SampleGenerator (ServiceDescriptionCollection services, XmlSchemas schemas)
  836.         {
  837.             descriptions = services;
  838.             this.schemas = schemas;
  839.             queue = new ArrayList ();
  840.         }
  841.         
  842.         public string GenerateMessage (Port port, OperationBinding obin, Operation oper, string protocol, bool generateInput)
  843.         {
  844.             OperationMessage msg = null;
  845.             foreach (OperationMessage opm in oper.Messages)
  846.             {
  847.                 if (opm is OperationInput && generateInput) msg = opm;
  848.                 else if (opm is OperationOutput && !generateInput) msg = opm;
  849.             }
  850.             if (msg == null) return null;
  851.             
  852.             switch (protocol) {
  853.                 case "Soap": return GenerateHttpSoapMessage (port, obin, oper, msg);
  854.                 case "HttpGet": return GenerateHttpGetMessage (port, obin, oper, msg);
  855.                 case "HttpPost": return GenerateHttpPostMessage (port, obin, oper, msg);
  856.             }
  857.             return "Unknown protocol";
  858.         }
  859.         
  860.         public string GenerateHttpSoapMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  861.         {
  862.             string req = "";
  863.             
  864.             if (msg is OperationInput)
  865.             {
  866.                 SoapAddressBinding sab = port.Extensions.Find (typeof(SoapAddressBinding)) as SoapAddressBinding;
  867.                 SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  868.                 req += "POST " + new Uri (sab.Location).AbsolutePath + "\n";
  869.                 req += "SOAPAction: " + sob.SoapAction + "\n";
  870.                 req += "Content-Type: text/xml; charset=utf-8\n";
  871.                 req += "Content-Length: " + GetLiteral ("string") + "\n";
  872.                 req += "Host: " + GetLiteral ("string") + "\n\n";
  873.             }
  874.             else
  875.             {
  876.                 req += "HTTP/1.0 200 OK\n";
  877.                 req += "Content-Type: text/xml; charset=utf-8\n";
  878.                 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
  879.             }
  880.             
  881.             req += GenerateSoapMessage (obin, oper, msg);
  882.             return req;
  883.         }
  884.         
  885.         public string GenerateHttpGetMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  886.         {
  887.             string req = "";
  888.             
  889.             if (msg is OperationInput)
  890.             {
  891.                 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
  892.                 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
  893.                 string location = new Uri (sab.Location).AbsolutePath + sob.Location + "?" + BuildQueryString (msg);
  894.                 req += "GET " + location + "\n";
  895.                 req += "Host: " + GetLiteral ("string");
  896.             }
  897.             else
  898.             {
  899.                 req += "HTTP/1.0 200 OK\n";
  900.                 req += "Content-Type: text/xml; charset=utf-8\n";
  901.                 req += "Content-Length: " + GetLiteral ("string") + "\n\n";
  902.             
  903.                 MimeXmlBinding mxb = (MimeXmlBinding) obin.Output.Extensions.Find (typeof(MimeXmlBinding)) as MimeXmlBinding;
  904.                 if (mxb == null) return req;
  905.                 
  906.                 Message message = descriptions.GetMessage (msg.Message);
  907.                 XmlQualifiedName ename = null;
  908.                 foreach (MessagePart part in message.Parts)
  909.                     if (part.Name == mxb.Part) ename = part.Element;
  910.                     
  911.                 if (ename == null) return req + GetLiteral("string");
  912.                 
  913.                 StringWriter sw = new StringWriter ();
  914.                 XmlTextWriter xtw = new XmlTextWriter (sw);
  915.                 xtw.Formatting = Formatting.Indented;
  916.                 currentUse = SoapBindingUse.Literal;
  917.                 WriteRootElementSample (xtw, ename);
  918.                 xtw.Close ();
  919.                 req += sw.ToString ();
  920.             }
  921.             
  922.             return req;
  923.         }
  924.         
  925.         public string GenerateHttpPostMessage (Port port, OperationBinding obin, Operation oper, OperationMessage msg)
  926.         {
  927.             string req = "";
  928.             
  929.             if (msg is OperationInput)
  930.             {
  931.                 HttpAddressBinding sab = port.Extensions.Find (typeof(HttpAddressBinding)) as HttpAddressBinding;
  932.                 HttpOperationBinding sob = obin.Extensions.Find (typeof(HttpOperationBinding)) as HttpOperationBinding;
  933.                 string location = new Uri (sab.Location).AbsolutePath + sob.Location;
  934.                 req += "POST " + location + "\n";
  935.                 req += "Content-Type: application/x-www-form-urlencoded\n";
  936.                 req += "Content-Length: " + GetLiteral ("string") + "\n";
  937.                 req += "Host: " + GetLiteral ("string") + "\n\n";
  938.                 req += BuildQueryString (msg);
  939.             }
  940.             else return GenerateHttpGetMessage (port, obin, oper, msg);
  941.             
  942.             return req;
  943.         }
  944.         
  945.         string BuildQueryString (OperationMessage opm)
  946.         {
  947.             string s = "";
  948.             Message msg = descriptions.GetMessage (opm.Message);
  949.             foreach (MessagePart part in msg.Parts)
  950.             {
  951.                 if (s.Length != 0) s += "&";
  952.                 s += part.Name + "=" + GetLiteral (part.Type.Name);
  953.             }
  954.             return s;
  955.         }
  956.         
  957.         public string GenerateSoapMessage (OperationBinding obin, Operation oper, OperationMessage msg)
  958.         {
  959.             SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  960.             SoapBindingStyle style = (sob != null) ? sob.Style : SoapBindingStyle.Document;
  961.             
  962.             MessageBinding msgbin = (msg is OperationInput) ? (MessageBinding) obin.Input : (MessageBinding)obin.Output;
  963.             SoapBodyBinding sbb = msgbin.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  964.             SoapBindingUse bodyUse = (sbb != null) ? sbb.Use : SoapBindingUse.Literal;
  965.             
  966.             StringWriter sw = new StringWriter ();
  967.             XmlTextWriter xtw = new XmlTextWriter (sw);
  968.             xtw.Formatting = Formatting.Indented;
  969.             
  970.             xtw.WriteStartDocument ();
  971.             xtw.WriteStartElement ("soap", "Envelope", SoapEnvelopeNamespace);
  972.             xtw.WriteAttributeString ("xmlns", "xsi", null, XmlSchema.InstanceNamespace);
  973.             xtw.WriteAttributeString ("xmlns", "xsd", null, XmlSchema.Namespace);
  974.             
  975.             if (bodyUse == SoapBindingUse.Encoded) 
  976.             {
  977.                 xtw.WriteAttributeString ("xmlns", "soapenc", null, SoapEncodingNamespace);
  978.                 xtw.WriteAttributeString ("xmlns", "tns", null, msg.Message.Namespace);
  979.             }
  980.  
  981.             // Serialize headers
  982.             
  983.             bool writtenHeader = false;
  984.             foreach (object ob in msgbin.Extensions)
  985.             {
  986.                 SoapHeaderBinding hb = ob as SoapHeaderBinding;
  987.                 if (hb == null) continue;
  988.                 
  989.                 if (!writtenHeader) {
  990.                     xtw.WriteStartElement ("soap", "Header", SoapEnvelopeNamespace);
  991.                     writtenHeader = true;
  992.                 }
  993.                 
  994.                 WriteHeader (xtw, hb);
  995.             }
  996.             
  997.             if (writtenHeader)
  998.                 xtw.WriteEndElement ();
  999.  
  1000.             // Serialize body
  1001.             xtw.WriteStartElement ("soap", "Body", SoapEnvelopeNamespace);
  1002.             
  1003.             currentUse = bodyUse;
  1004.             WriteBody (xtw, oper, msg, sbb, style);
  1005.             
  1006.             xtw.WriteEndElement ();
  1007.             xtw.WriteEndElement ();
  1008.             xtw.Close ();
  1009.             return sw.ToString ();
  1010.         }
  1011.         
  1012.         void WriteHeader (XmlTextWriter xtw, SoapHeaderBinding header)
  1013.         {
  1014.             Message msg = descriptions.GetMessage (header.Message);
  1015.             if (msg == null) throw new InvalidOperationException ("Message " + header.Message + " not found");
  1016.             MessagePart part = msg.Parts [header.Part];
  1017.             if (part == null) throw new InvalidOperationException ("Message part " + header.Part + " not found in message " + header.Message);
  1018.  
  1019.             currentUse = header.Use;
  1020.             
  1021.             if (currentUse == SoapBindingUse.Literal)
  1022.                 WriteRootElementSample (xtw, part.Element);
  1023.             else
  1024.                 WriteTypeSample (xtw, part.Type);
  1025.         }
  1026.         
  1027.         void WriteBody (XmlTextWriter xtw, Operation oper, OperationMessage opm, SoapBodyBinding sbb, SoapBindingStyle style)
  1028.         {
  1029.             Message msg = descriptions.GetMessage (opm.Message);
  1030.             if (msg.Parts.Count > 0 && msg.Parts[0].Name == "parameters")
  1031.             {
  1032.                 MessagePart part = msg.Parts[0];
  1033.                 if (part.Element == XmlQualifiedName.Empty)
  1034.                     WriteTypeSample (xtw, part.Type);
  1035.                 else
  1036.                     WriteRootElementSample (xtw, part.Element);
  1037.             }
  1038.             else
  1039.             {
  1040.                 string elemName = oper.Name;
  1041.                 string ns = "";
  1042.                 if (opm is OperationOutput) elemName += "Response";
  1043.                 
  1044.                 if (style == SoapBindingStyle.Rpc) {
  1045.                     xtw.WriteStartElement (elemName, sbb.Namespace);
  1046.                     ns = sbb.Namespace;
  1047.                 }
  1048.                     
  1049.                 foreach (MessagePart part in msg.Parts)
  1050.                 {
  1051.                     if (part.Element == XmlQualifiedName.Empty)
  1052.                     {
  1053.                         XmlSchemaElement elem = new XmlSchemaElement ();
  1054.                         elem.SchemaTypeName = part.Type;
  1055.                         elem.Name = part.Name;
  1056.                         WriteElementSample (xtw, ns, elem);
  1057.                     }
  1058.                     else
  1059.                         WriteRootElementSample (xtw, part.Element);
  1060.                 }
  1061.                 
  1062.                 if (style == SoapBindingStyle.Rpc)
  1063.                     xtw.WriteEndElement ();
  1064.             }
  1065.             WriteQueuedTypeSamples (xtw);
  1066.         }
  1067.         
  1068.         void WriteRootElementSample (XmlTextWriter xtw, XmlQualifiedName qname)
  1069.         {
  1070.             XmlSchemaElement elem = (XmlSchemaElement) schemas.Find (qname, typeof(XmlSchemaElement));
  1071.             if (elem == null) throw new InvalidOperationException ("Element not found: " + qname);
  1072.             WriteElementSample (xtw, qname.Namespace, elem);
  1073.         }
  1074.         
  1075.         void WriteElementSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
  1076.         {
  1077.             bool sharedAnnType = false;
  1078.             XmlQualifiedName root;
  1079.             
  1080.             if (!elem.RefName.IsEmpty) {
  1081.                 XmlSchemaElement refElem = FindRefElement (elem);
  1082.                 if (refElem == null) throw new InvalidOperationException ("Global element not found: " + elem.RefName);
  1083.                 root = elem.RefName;
  1084.                 elem = refElem;
  1085.                 sharedAnnType = true;
  1086.             }
  1087.             else
  1088.                 root = new XmlQualifiedName (elem.Name, ns);
  1089.             
  1090.             if (!elem.SchemaTypeName.IsEmpty)
  1091.             {
  1092.                 XmlSchemaComplexType st = FindComplexTyype (elem.SchemaTypeName);
  1093.                 if (st != null) 
  1094.                     WriteComplexTypeSample (xtw, st, root);
  1095.                 else
  1096.                 {
  1097.                     xtw.WriteStartElement (root.Name, root.Namespace);
  1098.                     if (currentUse == SoapBindingUse.Encoded) 
  1099.                         xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, elem.SchemaTypeName));
  1100.                     xtw.WriteString (GetLiteral (FindBuiltInType (elem.SchemaTypeName)));
  1101.                     xtw.WriteEndElement ();
  1102.                 }
  1103.             }
  1104.             else if (elem.SchemaType == null)
  1105.             {
  1106.                 xtw.WriteStartElement ("any");
  1107.                 xtw.WriteEndElement ();
  1108.             }
  1109.             else
  1110.                 WriteComplexTypeSample (xtw, (XmlSchemaComplexType) elem.SchemaType, root);
  1111.         }
  1112.         
  1113.         void WriteTypeSample (XmlTextWriter xtw, XmlQualifiedName qname)
  1114.         {
  1115.             XmlSchemaComplexType ctype = FindComplexTyype (qname);
  1116.             if (ctype != null) {
  1117.                 WriteComplexTypeSample (xtw, ctype, qname);
  1118.                 return;
  1119.             }
  1120.             
  1121.             XmlSchemaSimpleType stype = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  1122.             if (stype != null) {
  1123.                 WriteSimpleTypeSample (xtw, stype);
  1124.                 return;
  1125.             }
  1126.             
  1127.             xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
  1128.             throw new InvalidOperationException ("Type not found: " + qname);
  1129.         }
  1130.         
  1131.         void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName)
  1132.         {
  1133.             WriteComplexTypeSample (xtw, stype, rootName, -1);
  1134.         }
  1135.         
  1136.         void WriteComplexTypeSample (XmlTextWriter xtw, XmlSchemaComplexType stype, XmlQualifiedName rootName, int id)
  1137.         {
  1138.             string ns = rootName.Namespace;
  1139.             
  1140.             if (rootName.Name.IndexOf ("[]") != -1) rootName = arrayType;
  1141.             
  1142.             if (currentUse == SoapBindingUse.Encoded) {
  1143.                 string pref = xtw.LookupPrefix (rootName.Namespace);
  1144.                 if (pref == null) pref = "q1";
  1145.                 xtw.WriteStartElement (pref, rootName.Name, rootName.Namespace);
  1146.                 ns = "";
  1147.             }
  1148.             else
  1149.                 xtw.WriteStartElement (rootName.Name, rootName.Namespace);
  1150.             
  1151.             if (id != -1)
  1152.             {
  1153.                 xtw.WriteAttributeString ("id", "id" + id);
  1154.                 if (rootName != arrayType)
  1155.                     xtw.WriteAttributeString ("type", XmlSchema.InstanceNamespace, GetQualifiedNameString (xtw, rootName));
  1156.             }
  1157.             
  1158.             WriteComplexTypeAttributes (xtw, stype);
  1159.             WriteComplexTypeElements (xtw, ns, stype);
  1160.             
  1161.             xtw.WriteEndElement ();
  1162.         }
  1163.         
  1164.         void WriteComplexTypeAttributes (XmlTextWriter xtw, XmlSchemaComplexType stype)
  1165.         {
  1166.             WriteAttributes (xtw, stype.Attributes, stype.AnyAttribute);
  1167.         }
  1168.         
  1169.         void WriteComplexTypeElements (XmlTextWriter xtw, string ns, XmlSchemaComplexType stype)
  1170.         {
  1171.             if (stype.Particle != null)
  1172.                 WriteParticleComplexContent (xtw, ns, stype.Particle);
  1173.             else
  1174.             {
  1175.                 if (stype.ContentModel is XmlSchemaSimpleContent)
  1176.                     WriteSimpleContent (xtw, (XmlSchemaSimpleContent)stype.ContentModel);
  1177.                 else if (stype.ContentModel is XmlSchemaComplexContent)
  1178.                     WriteComplexContent (xtw, ns, (XmlSchemaComplexContent)stype.ContentModel);
  1179.             }
  1180.         }
  1181.  
  1182.         void WriteAttributes (XmlTextWriter xtw, XmlSchemaObjectCollection atts, XmlSchemaAnyAttribute anyat)
  1183.         {
  1184.             foreach (XmlSchemaObject at in atts)
  1185.             {
  1186.                 if (at is XmlSchemaAttribute)
  1187.                 {
  1188.                     string ns;
  1189.                     XmlSchemaAttribute attr = (XmlSchemaAttribute)at;
  1190.                     XmlSchemaAttribute refAttr = attr;
  1191.                     
  1192.                     // refAttr.Form; TODO
  1193.                     
  1194.                     if (!attr.RefName.IsEmpty) {
  1195.                         refAttr = FindRefAttribute (attr.RefName);
  1196.                         if (refAttr == null) throw new InvalidOperationException ("Global attribute not found: " + attr.RefName);
  1197.                     }
  1198.                     
  1199.                     string val;
  1200.                     if (!refAttr.SchemaTypeName.IsEmpty) val = FindBuiltInType (refAttr.SchemaTypeName);
  1201.                     else val = FindBuiltInType ((XmlSchemaSimpleType) refAttr.SchemaType);
  1202.                     
  1203.                     xtw.WriteAttributeString (refAttr.Name, val);
  1204.                 }
  1205.                 else if (at is XmlSchemaAttributeGroupRef)
  1206.                 {
  1207.                     XmlSchemaAttributeGroupRef gref = (XmlSchemaAttributeGroupRef)at;
  1208.                     XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  1209.                     WriteAttributes (xtw, grp.Attributes, grp.AnyAttribute);
  1210.                 }
  1211.             }
  1212.             
  1213.             if (anyat != null)
  1214.                 xtw.WriteAttributeString ("custom-attribute","value");
  1215.         }
  1216.         
  1217.         void WriteParticleComplexContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle)
  1218.         {
  1219.             WriteParticleContent (xtw, ns, particle, false);
  1220.         }
  1221.         
  1222.         void WriteParticleContent (XmlTextWriter xtw, string ns, XmlSchemaParticle particle, bool multiValue)
  1223.         {
  1224.             if (particle is XmlSchemaGroupRef)
  1225.                 particle = GetRefGroupParticle ((XmlSchemaGroupRef)particle);
  1226.  
  1227.             if (particle.MaxOccurs > 1) multiValue = true;
  1228.             
  1229.             if (particle is XmlSchemaSequence) {
  1230.                 WriteSequenceContent (xtw, ns, ((XmlSchemaSequence)particle).Items, multiValue);
  1231.             }
  1232.             else if (particle is XmlSchemaChoice) {
  1233.                 if (((XmlSchemaChoice)particle).Items.Count == 1)
  1234.                     WriteSequenceContent (xtw, ns, ((XmlSchemaChoice)particle).Items, multiValue);
  1235.                 else
  1236.                     WriteChoiceContent (xtw, ns, (XmlSchemaChoice)particle, multiValue);
  1237.             }
  1238.             else if (particle is XmlSchemaAll) {
  1239.                 WriteSequenceContent (xtw, ns, ((XmlSchemaAll)particle).Items, multiValue);
  1240.             }
  1241.         }
  1242.  
  1243.         void WriteSequenceContent (XmlTextWriter xtw, string ns, XmlSchemaObjectCollection items, bool multiValue)
  1244.         {
  1245.             foreach (XmlSchemaObject item in items)
  1246.                 WriteContentItem (xtw, ns, item, multiValue);
  1247.         }
  1248.         
  1249.         void WriteContentItem (XmlTextWriter xtw, string ns, XmlSchemaObject item, bool multiValue)
  1250.         {
  1251.             if (item is XmlSchemaGroupRef)
  1252.                 item = GetRefGroupParticle ((XmlSchemaGroupRef)item);
  1253.                     
  1254.             if (item is XmlSchemaElement)
  1255.             {
  1256.                 XmlSchemaElement elem = (XmlSchemaElement) item;
  1257.                 XmlSchemaElement refElem;
  1258.                 if (!elem.RefName.IsEmpty) refElem = FindRefElement (elem);
  1259.                 else refElem = elem;
  1260.  
  1261.                 int num = (elem.MaxOccurs == 1 && !multiValue) ? 1 : 2;
  1262.                 for (int n=0; n<num; n++)
  1263.                 {
  1264.                     if (currentUse == SoapBindingUse.Literal)
  1265.                         WriteElementSample (xtw, ns, refElem);
  1266.                     else
  1267.                         WriteRefTypeSample (xtw, ns, refElem);
  1268.                 }
  1269.             }
  1270.             else if (item is XmlSchemaAny)
  1271.             {
  1272.                 xtw.WriteString (GetLiteral ("xml"));
  1273.             }
  1274.             else if (item is XmlSchemaParticle) {
  1275.                 WriteParticleContent (xtw, ns, (XmlSchemaParticle)item, multiValue);
  1276.             }
  1277.         }
  1278.         
  1279.         void WriteChoiceContent (XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
  1280.         {
  1281.             foreach (XmlSchemaObject item in choice.Items)
  1282.                 WriteContentItem (xtw, ns, item, multiValue);
  1283.         }
  1284.  
  1285.         void WriteSimpleContent (XmlTextWriter xtw, XmlSchemaSimpleContent content)
  1286.         {
  1287.             XmlSchemaSimpleContentExtension ext = content.Content as XmlSchemaSimpleContentExtension;
  1288.             if (ext != null)
  1289.                 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
  1290.                 
  1291.             XmlQualifiedName qname = GetContentBaseType (content.Content);
  1292.             xtw.WriteString (GetLiteral (FindBuiltInType (qname)));
  1293.         }
  1294.  
  1295.         string FindBuiltInType (XmlQualifiedName qname)
  1296.         {
  1297.             if (qname.Namespace == XmlSchema.Namespace)
  1298.                 return qname.Name;
  1299.  
  1300.             XmlSchemaComplexType ct = FindComplexTyype (qname);
  1301.             if (ct != null)
  1302.             {
  1303.                 XmlSchemaSimpleContent sc = ct.ContentModel as XmlSchemaSimpleContent;
  1304.                 if (sc == null) throw new InvalidOperationException ("Invalid schema");
  1305.                 return FindBuiltInType (GetContentBaseType (sc.Content));
  1306.             }
  1307.             
  1308.             XmlSchemaSimpleType st = (XmlSchemaSimpleType) schemas.Find (qname, typeof(XmlSchemaSimpleType));
  1309.             if (st != null)
  1310.                 return FindBuiltInType (st);
  1311.  
  1312.             throw new InvalidOperationException ("Definition of type " + qname + " not found");
  1313.         }
  1314.  
  1315.         string FindBuiltInType (XmlSchemaSimpleType st)
  1316.         {
  1317.             if (st.Content is XmlSchemaSimpleTypeRestriction) {
  1318.                 return FindBuiltInType (GetContentBaseType (st.Content));
  1319.             }
  1320.             else if (st.Content is XmlSchemaSimpleTypeList) {
  1321.                 string s = FindBuiltInType (GetContentBaseType (st.Content));
  1322.                 return s + " " + s + " ...";
  1323.             }
  1324.             else if (st.Content is XmlSchemaSimpleTypeUnion)
  1325.             {
  1326.                 //Check if all types of the union are equal. If not, then will use anyType.
  1327.                 XmlSchemaSimpleTypeUnion uni = (XmlSchemaSimpleTypeUnion) st.Content;
  1328.                 string utype = null;
  1329.  
  1330.                 // Anonymous types are unique
  1331.                 if (uni.BaseTypes.Count != 0 && uni.MemberTypes.Length != 0)
  1332.                     return "string";
  1333.  
  1334.                 foreach (XmlQualifiedName mt in uni.MemberTypes)
  1335.                 {
  1336.                     string qn = FindBuiltInType (mt);
  1337.                     if (utype != null && qn != utype) return "string";
  1338.                     else utype = qn;
  1339.                 }
  1340.                 return utype;
  1341.             }
  1342.             else
  1343.                 return "string";
  1344.         }
  1345.         
  1346.  
  1347.         XmlQualifiedName GetContentBaseType (XmlSchemaObject ob)
  1348.         {
  1349.             if (ob is XmlSchemaSimpleContentExtension)
  1350.                 return ((XmlSchemaSimpleContentExtension)ob).BaseTypeName;
  1351.             else if (ob is XmlSchemaSimpleContentRestriction)
  1352.                 return ((XmlSchemaSimpleContentRestriction)ob).BaseTypeName;
  1353.             else if (ob is XmlSchemaSimpleTypeRestriction)
  1354.                 return ((XmlSchemaSimpleTypeRestriction)ob).BaseTypeName;
  1355.             else if (ob is XmlSchemaSimpleTypeList)
  1356.                 return ((XmlSchemaSimpleTypeList)ob).ItemTypeName;
  1357.             else
  1358.                 return null;
  1359.         }
  1360.  
  1361.         void WriteComplexContent (XmlTextWriter xtw, string ns, XmlSchemaComplexContent content)
  1362.         {
  1363.             XmlQualifiedName qname;
  1364.  
  1365.             XmlSchemaComplexContentExtension ext = content.Content as XmlSchemaComplexContentExtension;
  1366.             if (ext != null) qname = ext.BaseTypeName;
  1367.             else {
  1368.                 XmlSchemaComplexContentRestriction rest = (XmlSchemaComplexContentRestriction)content.Content;
  1369.                 qname = rest.BaseTypeName;
  1370.                 if (qname == arrayType) {
  1371.                     ParseArrayType (rest, out qname);
  1372.                     XmlSchemaElement elem = new XmlSchemaElement ();
  1373.                     elem.Name = "Item";
  1374.                     elem.SchemaTypeName = qname;
  1375.                     
  1376.                     xtw.WriteAttributeString ("arrayType", SoapEncodingNamespace, qname.Name + "[2]");
  1377.                     WriteContentItem (xtw, ns, elem, true);
  1378.                     return;
  1379.                 }
  1380.             }
  1381.             
  1382.             // Add base map members to this map
  1383.             XmlSchemaComplexType ctype = FindComplexTyype (qname);
  1384.             WriteComplexTypeAttributes (xtw, ctype);
  1385.             
  1386.             if (ext != null) {
  1387.                 // Add the members of this map
  1388.                 WriteAttributes (xtw, ext.Attributes, ext.AnyAttribute);
  1389.                 if (ext.Particle != null)
  1390.                     WriteParticleComplexContent (xtw, ns, ext.Particle);
  1391.             }
  1392.             
  1393.             WriteComplexTypeElements (xtw, ns, ctype);
  1394.         }
  1395.         
  1396.         void ParseArrayType (XmlSchemaComplexContentRestriction rest, out XmlQualifiedName qtype)
  1397.         {
  1398.             XmlSchemaAttribute arrayTypeAt = FindArrayAttribute (rest.Attributes);
  1399.             XmlAttribute[] uatts = arrayTypeAt.UnhandledAttributes;
  1400.             if (uatts == null || uatts.Length == 0) throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
  1401.             
  1402.             XmlAttribute xat = null;
  1403.             foreach (XmlAttribute at in uatts)
  1404.                 if (at.LocalName == "arrayType" && at.NamespaceURI == WsdlNamespace)
  1405.                     { xat = at; break; }
  1406.             
  1407.             if (xat == null) 
  1408.                 throw new InvalidOperationException ("arrayType attribute not specified in array declaration");
  1409.             
  1410.             string arrayType = xat.Value;
  1411.             string type, ns;
  1412.             int i = arrayType.LastIndexOf (":");
  1413.             if (i == -1) ns = "";
  1414.             else ns = arrayType.Substring (0,i);
  1415.             
  1416.             int j = arrayType.IndexOf ("[", i+1);
  1417.             if (j == -1) throw new InvalidOperationException ("Cannot parse WSDL array type: " + arrayType);
  1418.             type = arrayType.Substring (i+1);
  1419.             type = type.Substring (0, type.Length-2);
  1420.             
  1421.             qtype = new XmlQualifiedName (type, ns);
  1422.         }
  1423.         
  1424.         XmlSchemaAttribute FindArrayAttribute (XmlSchemaObjectCollection atts)
  1425.         {
  1426.             foreach (object ob in atts)
  1427.             {
  1428.                 XmlSchemaAttribute att = ob as XmlSchemaAttribute;
  1429.                 if (att != null && att.RefName == arrayTypeRefName) return att;
  1430.                 
  1431.                 XmlSchemaAttributeGroupRef gref = ob as XmlSchemaAttributeGroupRef;
  1432.                 if (gref != null)
  1433.                 {
  1434.                     XmlSchemaAttributeGroup grp = (XmlSchemaAttributeGroup) schemas.Find (gref.RefName, typeof(XmlSchemaAttributeGroup));
  1435.                     att = FindArrayAttribute (grp.Attributes);
  1436.                     if (att != null) return att;
  1437.                 }
  1438.             }
  1439.             return null;
  1440.         }
  1441.         
  1442.         void WriteSimpleTypeSample (XmlTextWriter xtw, XmlSchemaSimpleType stype)
  1443.         {
  1444.             xtw.WriteString (GetLiteral (FindBuiltInType (stype)));
  1445.         }
  1446.         
  1447.         XmlSchemaParticle GetRefGroupParticle (XmlSchemaGroupRef refGroup)
  1448.         {
  1449.             XmlSchemaGroup grp = (XmlSchemaGroup) schemas.Find (refGroup.RefName, typeof (XmlSchemaGroup));
  1450.             return grp.Particle;
  1451.         }
  1452.  
  1453.         XmlSchemaElement FindRefElement (XmlSchemaElement elem)
  1454.         {
  1455.             if (elem.RefName.Namespace == XmlSchema.Namespace)
  1456.             {
  1457.                 if (anyElement != null) return anyElement;
  1458.                 anyElement = new XmlSchemaElement ();
  1459.                 anyElement.Name = "any";
  1460.                 anyElement.SchemaTypeName = anyType;
  1461.                 return anyElement;
  1462.             }
  1463.             return (XmlSchemaElement) schemas.Find (elem.RefName, typeof(XmlSchemaElement));
  1464.         }
  1465.         
  1466.         XmlSchemaAttribute FindRefAttribute (XmlQualifiedName refName)
  1467.         {
  1468.             if (refName.Namespace == XmlSchema.Namespace)
  1469.             {
  1470.                 XmlSchemaAttribute at = new XmlSchemaAttribute ();
  1471.                 at.Name = refName.Name;
  1472.                 at.SchemaTypeName = new XmlQualifiedName ("string",XmlSchema.Namespace);
  1473.                 return at;
  1474.             }
  1475.             return (XmlSchemaAttribute) schemas.Find (refName, typeof(XmlSchemaAttribute));
  1476.         }
  1477.         
  1478.         void WriteRefTypeSample (XmlTextWriter xtw, string ns, XmlSchemaElement elem)
  1479.         {
  1480.             if (elem.SchemaTypeName.Namespace == XmlSchema.Namespace || schemas.Find (elem.SchemaTypeName, typeof(XmlSchemaSimpleType)) != null)
  1481.                 WriteElementSample (xtw, ns, elem);
  1482.             else
  1483.             {
  1484.                 xtw.WriteStartElement (elem.Name, ns);
  1485.                 xtw.WriteAttributeString ("href", "#id" + (queue.Count+1));
  1486.                 xtw.WriteEndElement ();
  1487.                 queue.Add (new EncodedType (ns, elem));
  1488.             }
  1489.         }
  1490.         
  1491.         void WriteQueuedTypeSamples (XmlTextWriter xtw)
  1492.         {
  1493.             for (int n=0; n<queue.Count; n++)
  1494.             {
  1495.                 EncodedType ec = (EncodedType) queue[n];
  1496.                 XmlSchemaComplexType st = FindComplexTyype (ec.Element.SchemaTypeName);
  1497.                 WriteComplexTypeSample (xtw, st, ec.Element.SchemaTypeName, n+1);
  1498.             }
  1499.         }
  1500.         
  1501.         XmlSchemaComplexType FindComplexTyype (XmlQualifiedName qname)
  1502.         {
  1503.             if (qname.Name.IndexOf ("[]") != -1)
  1504.             {
  1505.                 XmlSchemaComplexType stype = new XmlSchemaComplexType ();
  1506.                 stype.ContentModel = new XmlSchemaComplexContent ();
  1507.                 
  1508.                 XmlSchemaComplexContentRestriction res = new XmlSchemaComplexContentRestriction ();
  1509.                 stype.ContentModel.Content = res;
  1510.                 res.BaseTypeName = arrayType;
  1511.                 
  1512.                 XmlSchemaAttribute att = new XmlSchemaAttribute ();
  1513.                 att.RefName = arrayTypeRefName;
  1514.                 res.Attributes.Add (att);
  1515.                 
  1516.                 XmlAttribute xat = document.CreateAttribute ("arrayType", WsdlNamespace);
  1517.                 xat.Value = qname.Namespace + ":" + qname.Name;
  1518.                 att.UnhandledAttributes = new XmlAttribute[] {xat};
  1519.                 return stype;
  1520.             }
  1521.                 
  1522.             return (XmlSchemaComplexType) schemas.Find (qname, typeof(XmlSchemaComplexType));
  1523.         }
  1524.         
  1525.         string GetQualifiedNameString (XmlTextWriter xtw, XmlQualifiedName qname)
  1526.         {
  1527.             string pref = xtw.LookupPrefix (qname.Namespace);
  1528.             if (pref != null) return pref + ":" + qname.Name;
  1529.             
  1530.             xtw.WriteAttributeString ("xmlns", "q1", null, qname.Namespace);
  1531.             return "q1:" + qname.Name;
  1532.         }
  1533.                 
  1534.         protected virtual string GetLiteral (string s)
  1535.         {
  1536.             return s;
  1537.         }
  1538.  
  1539.         void GetOperationFormat (OperationBinding obin, out SoapBindingStyle style, out SoapBindingUse use)
  1540.         {
  1541.             style = SoapBindingStyle.Document;
  1542.             use = SoapBindingUse.Literal;
  1543.             SoapOperationBinding sob = obin.Extensions.Find (typeof(SoapOperationBinding)) as SoapOperationBinding;
  1544.             if (sob != null) {
  1545.                 style = sob.Style;
  1546.                 SoapBodyBinding sbb = obin.Input.Extensions.Find (typeof(SoapBodyBinding)) as SoapBodyBinding;
  1547.                 if (sbb != null)
  1548.                     use = sbb.Use;
  1549.             }
  1550.         }
  1551.     }
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557. </script>
  1558.  
  1559. <head runat="server">
  1560.     <link rel="alternate" type="text/xml" href="<%=Request.FilePath%>?disco"/>
  1561.  
  1562.     <title><%=WebServiceName%> Web Service</title>
  1563.     <style type="text/css">
  1564.         BODY { font-family: Arial; margin-left: 20px; margin-top: 20px; font-size: x-small}
  1565.         TABLE { font-size: x-small }
  1566.         .title { color:dimgray; font-family: Arial; font-size:20pt; font-weight:900}
  1567.         .operationTitle { color:dimgray; font-family: Arial; font-size:15pt; font-weight:900}
  1568.         .method { font-size: x-small }
  1569.         .bindingLabel { font-size: x-small; font-weight:bold; color:darkgray; line-height:8pt; display:block; margin-bottom:3px }
  1570.         .label { font-size: small; font-weight:bold; color:darkgray }
  1571.         .paramTable { font-size: x-small }
  1572.         .paramTable TR { background-color: gainsboro }
  1573.         .paramFormTable { font-size: x-small; padding: 10px; background-color: gainsboro }
  1574.         .paramFormTable TR { background-color: gainsboro }
  1575.         .paramInput { border: solid 1px gray }
  1576.         .button {border: solid 1px gray }
  1577.         .smallSeparator { height:3px; overflow:hidden }
  1578.         .panel { background-color:whitesmoke; border: solid 1px silver; border-top: solid 1px silver  }
  1579.         .codePanel { background-color: white; font-size:x-small; padding:7px; border:solid 1px silver}
  1580.         .code-xml { font-size:10pt; font-family:courier }
  1581.         .code-cs { font-size:10pt; font-family:courier }
  1582.         .code-vb { font-size:10pt; font-family:courier }
  1583.         .tabLabelOn { font-weight:bold }
  1584.         .tabLabelOff {color: darkgray }
  1585.         .literal-placeholder {color: darkblue; font-weight:bold}
  1586.         A:link { color: black; }
  1587.         A:visited { color: black; }
  1588.         A:active { color: black; }
  1589.         A:hover { color: blue }
  1590.     </style>
  1591.     
  1592. <script>
  1593. function clearForm ()
  1594. {
  1595.     document.getElementById("testFormResult").style.display="none";
  1596. }
  1597. </script>
  1598.  
  1599. </head>
  1600.  
  1601. <body>
  1602. <div class="title" style="margin-left:20px">
  1603. <span class="label">Web Service</span><br>
  1604. <%=WebServiceName%>
  1605. </div>
  1606.  
  1607. <!--
  1608.     **********************************************************
  1609.     Left panel
  1610. -->
  1611.  
  1612. <table border="0" width="100%" cellpadding="15px" cellspacing="15px">
  1613. <tr valign="top"><td width="150px" class="panel">
  1614. <div style="width:150px"></div>
  1615. <a class="method" href='<%=PageName%>'>Overview</a><br>
  1616. <div class="smallSeparator"></div>
  1617. <a class="method" href='<%=PageName + "?" + GetPageContext("wsdl")%>'>Service Description</a>
  1618. <div class="smallSeparator"></div>
  1619. <a class="method" href='<%=PageName + "?" + GetPageContext("proxy")%>'>Client proxy</a>
  1620. <br><br>
  1621.     <asp:repeater id="BindingsRepeater" runat=server>
  1622.         <itemtemplate name="itemtemplate">
  1623.             <span class="bindingLabel"><%#FormatBindingName(DataBinder.Eval(Container.DataItem, "Name").ToString())%></span>
  1624.             <asp:repeater id="OperationsRepeater" runat=server datasource='<%# ((Binding)Container.DataItem).Operations %>'>
  1625.                 <itemtemplate>
  1626.                     <a class="method" href="<%=PageName%>?<%=GetTabContext("op",null)%>op=<%#GetOpName(Container.DataItem)%>&bnd=<%#DataBinder.Eval(Container.DataItem, "Binding.Name")%>"><%#GetOpName(Container.DataItem)%></a>
  1627.                     <div class="smallSeparator"></div>
  1628.                 </itemtemplate>
  1629.             </asp:repeater>
  1630.             <br>
  1631.         </itemtemplate>
  1632.     </asp:repeater>
  1633.  
  1634. </td><td class="panel">
  1635.  
  1636. <% if (CurrentPage == "main") {%>
  1637.  
  1638. <!--
  1639.     **********************************************************
  1640.     Web service overview
  1641. -->
  1642.  
  1643.     <p class="label">Web Service Overview</p>
  1644.     <%=WebServiceDescription%>
  1645.     <br/><br/>
  1646.     <% if (ProfileViolations != null && ProfileViolations.Count > 0) { %>
  1647.         <p class="label">Basic Profile Conformance</p>
  1648.         This web service does not conform to WS-I Basic Profile v1.1
  1649.     <%
  1650.         Response.Write ("<ul>");
  1651.         foreach (BasicProfileViolation vio in ProfileViolations) {
  1652.             Response.Write ("<li><b>" + vio.NormativeStatement + "</b>: " + vio.Details);
  1653.             Response.Write ("<ul>");
  1654.             foreach (string ele in vio.Elements)
  1655.                 Response.Write ("<li>" + ele + "</li>");
  1656.             Response.Write ("</ul>");
  1657.             Response.Write ("</li>");
  1658.         }
  1659.         Response.Write ("</ul>");
  1660.     }%>
  1661.  
  1662. <%} if (DefaultBinding == null) {%>
  1663. This service does not contain any public web method.
  1664. <%} else if (CurrentPage == "op") {%>
  1665.  
  1666. <!--
  1667.     **********************************************************
  1668.     Operation description
  1669. -->
  1670.  
  1671.     <span class="operationTitle"><%=CurrentOperationName%></span>
  1672.     <br><br>
  1673.     <% WriteTabs (); %>
  1674.     <br><br><br>
  1675.     
  1676.     <% if (CurrentTab == "main") { %>
  1677.         <span class="label">Input Parameters</span>
  1678.         <div class="smallSeparator"></div>
  1679.         <% if (InParams.Count == 0) { %>
  1680.             No input parameters<br>
  1681.         <% } else { %>
  1682.             <table class="paramTable" cellspacing="1" cellpadding="5">
  1683.             <asp:repeater id="InputParamsRepeater" runat=server>
  1684.                 <itemtemplate>
  1685.                     <tr>
  1686.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  1687.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  1688.                     </tr>
  1689.                 </itemtemplate>
  1690.             </asp:repeater>
  1691.             </table>
  1692.         <% } %>
  1693.         <br>
  1694.         
  1695.         <% if (OutParams.Count > 0) { %>
  1696.         <span class="label">Output Parameters</span>
  1697.             <div class="smallSeparator"></div>
  1698.             <table class="paramTable" cellspacing="1" cellpadding="5">
  1699.             <asp:repeater id="OutputParamsRepeater" runat=server>
  1700.                 <itemtemplate>
  1701.                     <tr>
  1702.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Name")%></td>
  1703.                     <td width="150"><%#DataBinder.Eval(Container.DataItem, "Type")%></td>
  1704.                     </tr>
  1705.                 </itemtemplate>
  1706.             </asp:repeater>
  1707.             </table>
  1708.         <br>
  1709.         <% } %>
  1710.         
  1711.         <span class="label">Remarks</span>
  1712.         <div class="smallSeparator"></div>
  1713.         <%=OperationDocumentation%>
  1714.         <br><br>
  1715.         <span class="label">Technical information</span>
  1716.         <div class="smallSeparator"></div>
  1717.         Format: <%=CurrentOperationFormat%>
  1718.         <br>Supported protocols: <%=CurrentOperationProtocols%>
  1719.     <% } %>
  1720.     
  1721. <!--
  1722.     **********************************************************
  1723.     Operation description - Test form
  1724. -->
  1725.  
  1726.     <% if (CurrentTab == "test") { 
  1727.         if (CurrentOperationSupportsTest) {%>
  1728.             Enter values for the parameters and click the 'Invoke' button to test this method:<br><br>
  1729.             <form action="<%=PageName%>" method="GET">
  1730.             <input type="hidden" name="page" value="<%=CurrentPage%>">
  1731.             <input type="hidden" name="tab" value="<%=CurrentTab%>">
  1732.             <input type="hidden" name="op" value="<%=CurrentOperationName%>">
  1733.             <input type="hidden" name="bnd" value="<%=CurrentOperationBinding%>">
  1734.             <input type="hidden" name="ext" value="testform">
  1735.             <table class="paramFormTable" cellspacing="0" cellpadding="3">
  1736.             <asp:repeater id="InputFormParamsRepeater" runat=server>
  1737.                 <itemtemplate>
  1738.                     <tr>
  1739.                     <td><%#DataBinder.Eval(Container.DataItem, "Name")%>: </td>
  1740.                     <td width="150"><input class="paramInput" type="text" size="20" name="<%#DataBinder.Eval(Container.DataItem, "Name")%>"></td>
  1741.                     </tr>
  1742.                 </itemtemplate>
  1743.             </asp:repeater>
  1744.             <tr><td></td><td><input class="button" type="submit" value="Invoke"> <input class="button" type="button" onclick="clearForm()" value="Clear"></td></tr>
  1745.             </table>
  1746.             </form>
  1747.             <div id="testFormResult" style="display:<%= (HasFormResult?"block":"none") %>">
  1748.             The web service returned the following result:<br/><br/>
  1749.             <div class="codePanel"><%=GetTestResult()%></div>
  1750.             </div>
  1751.         <% } else {%>
  1752.         The test form is not available for this operation because it has parameters with a complex structure.
  1753.         <% } %>
  1754.     <% } %>
  1755.     
  1756. <!--
  1757.     **********************************************************
  1758.     Operation description - Message Layout
  1759. -->
  1760.  
  1761.     <% if (CurrentTab == "msg") { %>
  1762.         
  1763.         The following are sample SOAP requests and responses for each protocol supported by this method:
  1764.             <br/><br/>
  1765.         
  1766.         <% if (IsOperationSupported ("Soap")) { %>
  1767.             <span class="label">Soap</span>
  1768.             <br/><br/>
  1769.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", true)%></div></div>
  1770.             <br/>
  1771.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("Soap", false)%></div></div>
  1772.             <br/>
  1773.         <% } %>
  1774.         <% if (IsOperationSupported ("HttpGet")) { %>
  1775.             <span class="label">HTTP Get</span>
  1776.             <br/><br/>
  1777.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", true)%></div></div>
  1778.             <br/>
  1779.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpGet", false)%></div></div>
  1780.             <br/>
  1781.         <% } %>
  1782.         <% if (IsOperationSupported ("HttpPost")) { %>
  1783.             <span class="label">HTTP Post</span>
  1784.             <br/><br/>
  1785.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", true)%></div></div>
  1786.             <br/>
  1787.             <div class="codePanel"><div class="code-xml"><%=GenerateOperationMessages ("HttpPost", false)%></div></div>
  1788.             <br/>
  1789.         <% } %>
  1790.         
  1791.     <% } %>
  1792. <%} else if (CurrentPage == "proxy") {%>
  1793. <!--
  1794.     **********************************************************
  1795.     Client Proxy
  1796. -->
  1797.     <form action="<%=PageName%>" name="langForm" method="GET">
  1798.         Select the language for which you want to generate a proxy 
  1799.         <input type="hidden" name="page" value="<%=CurrentPage%>"> 
  1800.         <SELECT name="lang" onchange="langForm.submit()">
  1801.             <%=GetOptionSel("cs",CurrentLanguage)%>C#</option>
  1802.             <%=GetOptionSel("vb",CurrentLanguage)%>Visual Basic</option>
  1803.         </SELECT>
  1804.           
  1805.     </form>
  1806.     <br>
  1807.     <span class="label"><%=CurrentProxytName%></span>   
  1808.     <a href="<%=PageName + "?code=" + CurrentLanguage%>">Download</a>
  1809.     <br><br>
  1810.     <div class="codePanel">
  1811.     <div class="code-<%=CurrentLanguage%>"><%=GetProxyCode ()%></div>
  1812.     </div>
  1813. <%} else if (CurrentPage == "wsdl") {%>
  1814. <!--
  1815.     **********************************************************
  1816.     Service description
  1817. -->
  1818.     <% if (descriptions.Count > 1 || schemas.Count > 1) {%>
  1819.     The description of this web service is composed by several documents. Click on the document you want to see:
  1820.     
  1821.     <ul>
  1822.     <% 
  1823.         for (int n=0; n<descriptions.Count; n++)
  1824.             Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=wsdl&docind=" + n + "'>WSDL document " + descriptions[n].TargetNamespace + "</a></li>");
  1825.         for (int n=0; n<schemas.Count; n++)
  1826.             Response.Write ("<li><a href='" + PageName + "?" + GetPageContext(null) + "doctype=schema&docind=" + n + "'>Xml Schema " + schemas[n].TargetNamespace + "</a></li>");
  1827.     %>
  1828.     </ul>
  1829.     
  1830.     <%} else {%>
  1831.     <%}%>
  1832.     <br>
  1833.     <span class="label"><%=CurrentDocumentName%></span>   
  1834.     <a href="<%=PageName + "?" + CurrentDocType + "=" + CurrentDocInd %>">Download</a>
  1835.     <br><br>
  1836.     <div class="codePanel">
  1837.     <div class="code-xml"><%=GenerateDocument ()%></div>
  1838.     </div>
  1839.  
  1840. <%}%>
  1841.  
  1842. <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  1843. </td>
  1844. <td width="20px"></td>
  1845. </tr>
  1846.  
  1847. </table>
  1848. </body>
  1849. </html>
  1850.